package com.ysd.Servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ysd.dao.impl.UserinfoDaoimpl;
import com.ysd.entity.Userinfo;
import com.ysd.util.Result;

/**
 * Servlet implementation class MessageServlet
 */
public class MessageServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	response.setCharacterEncoding("UTF-8");
	PrintWriter out=response.getWriter();	
		
	String username=request.getParameter("username");
	String phone=request.getParameter("phone");
	String email=request.getParameter("email");
	String content=request.getParameter("content");
	
	
	Date date = new Date();
	SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	String time=formatter.format(date);
	Userinfo user=new Userinfo(username, phone, email, content,time,"未读");
	
	
	UserinfoDaoimpl userinfo=new UserinfoDaoimpl();
	int n=userinfo.addUserinfo(user);
	if(n>0) {
		out.print(Result.toClient(true, "留言成功", ""));
	}else {
		out.print(Result.toClient(false, "留言失败", "服务器错误"));
	}
		

		
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
